from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.kbd import Back, Button, Cancel, Group

from src.presentation.tg_bot.dialogs.getters.orders import subscription_summary_getter
from src.presentation.tg_bot.dialogs.widgets import LocaleText
from src.presentation.tg_bot.states import BuyProxySubscriptionSG

from ...common_handlers import add_order_vpn
from .handlers import set_subscription_period

select_plan_window = Window(
    LocaleText("select-subscription-plan"),
    Group(
        Button(LocaleText("one_day"), id="one_day", on_click=set_subscription_period),
        Button(LocaleText("two_weeks"), id="two_weeks", on_click=set_subscription_period),
        Button(LocaleText("one_month"), id="one_month", on_click=set_subscription_period),
        width=2,
    ),
    Cancel(LocaleText("back-btn")),
    state=BuyProxySubscriptionSG.select_plan,
)

create_order_window = Window(
    LocaleText("order-overview"),
    LocaleText("selected-period", period="{period}"),
    LocaleText("order-summ", order_summ="{subscription_summ}$"),
    Button(
        LocaleText("confirm-btn"),
        id="confirm_order_button",
        on_click=add_order_vpn,
    ),
    Back(LocaleText("back-btn")),
    Cancel(LocaleText("cancel-btn")),
    state=BuyProxySubscriptionSG.create_order,
    getter=subscription_summary_getter,
)

buy_subscription_dialog = Dialog(select_plan_window, create_order_window)
